package com.youedata.modular.controller;

import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youedata.base.auth.annotion.Permission;
import com.youedata.base.log.BussinessLog;
import com.youedata.base.pojo.page.LayuiPageFactory;
import com.youedata.base.tips.DCResponse;
import com.youedata.modular.entity.GoodsInfo;
import com.youedata.modular.entity.SyTravelInfo;
import com.youedata.modular.model.dto.SyTravelInfoDTO;
import com.youedata.modular.service.ISyTravelInfoService;
import com.youedata.sys.core.constant.Const;
import com.youedata.sys.core.constant.dictmap.UserDict;
import com.youedata.sys.core.constant.state.ManagerStatus;
import com.youedata.sys.core.exception.enums.BizExceptionEnum;
import com.youedata.sys.core.util.UserHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 建湖文广旅控制器
 *
 * @author hst
 * @date 2021-08-06 22:07:52
 */
@Controller
@Api(value = "/syTravelInfo", tags = "建湖文广旅管理")
@RequestMapping("/syTravelInfo")
public class SyTravelInfoController {

    private String PREFIX = "/syTravelInfo";

    @Autowired
    private ISyTravelInfoService syTravelInfoService;

    /**
     * 新增
     *
     * @author hst
     * @date 2021-08-06
     */
    @ResponseBody
    @PostMapping("/addItem")
    @ApiOperation(value = "新增")
    public DCResponse<Void> addItem(SyTravelInfoDTO syTravelInfoDto) {
//        SyTravelInfo syTravelInfo = new SyTravelInfo();
//        BeanUtils.copyProperties(syTravelInfoDto, syTravelInfo);
//        syTravelInfo.setCreateUser(UserHolder.getUserId());
//        syTravelInfo.setCreateTime(LocalDate.from(LocalDateTime.now()));
       this.syTravelInfoService.saveSelective(syTravelInfoDto);
        return DCResponse.ok(null);
    }

    /**
     * 根据主键删除
     *
     * @author hst
     * @date 2021-08-06
     */
    @ResponseBody
    @PostMapping("/delete")
    @ApiOperation("删除")
    public DCResponse<Void> delete(@RequestParam("id") String id) {
        this.syTravelInfoService.removeById(id);
        return DCResponse.ok(null);
    }

    /**
     * 修改
     *
     * @author hst
     * @date 2021-08-06
     */
    @ResponseBody
    @PostMapping("/editItem")
    @ApiOperation("根据ID修改信息")
    public DCResponse<Void> editItem(SyTravelInfoDTO syTravelInfoDto) {
//        SyTravelInfo syTravelInfo = new SyTravelInfo();
//       BeanUtils.copyProperties(syTravelInfoDto, syTravelInfo);
//        syTravelInfo.setUpdateUser(Long.valueOf(UserHolder.getUserId()));
//        syTravelInfo.setUpdateTime(LocalDateTime.now());
//        this.syTravelInfoService.updateById(syTravelInfo);
        this.syTravelInfoService.updateSyTravelInfo(syTravelInfoDto);
        return DCResponse.ok(null);
    }



    /**
     * 根据主键查询单条详情
     *
     * @author hst
     * @date 2021-08-06
     */
    @ResponseBody
    @PostMapping("/detail")
    @ApiOperation(value = "根据主键查询单条详情")
    public ResponseData detail(@RequestParam("id") String id) {
        return ResponseData.success(this.syTravelInfoService.detailById(id,"N"));
    }

    /**
     * 修改商品状态
     *
     * @author hao.yan
     * @Date 2021/08/25 22:44
     */
    @ResponseBody
    @RequestMapping("/changeRecommend")
    @ApiOperation(value = "修改商品状态")
//    @Permission(Const.ADMIN_NAME)
    public ResponseData changeRecommend(Long id, Boolean flag) {
        SyTravelInfo syTravelInfo = this.syTravelInfoService.getById(id);
        if (com.youedata.util.ToolUtil.isNotEmpty(syTravelInfo)) {
            syTravelInfo.setRecommend(flag ? "热点推荐" : "非热点推荐");
        }
        this.syTravelInfoService.updateById(syTravelInfo);
        return ResponseData.success(syTravelInfo);
    }
    /**
     * 分页查询列表
     *
     * @author hst
     * @date 2021-08-06
     */
    @ResponseBody
    @GetMapping("/list")
    @ApiOperation(value = "分页查询列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "page", value = "当前页码", required = true, defaultValue = "1", paramType = "query", dataType = "int", example = "1"),
        @ApiImplicitParam(name = "limit", value = "每页多少条数据", required = true, defaultValue = "10", paramType = "query", dataType = "int", example = "20")
    })
    public Object list(SyTravelInfoDTO syTravelInfoDto) {
        SyTravelInfo syTravelInfo = new SyTravelInfo();

        //过滤空字符串
        syTravelInfoDto.setName(StringUtils.isEmpty(syTravelInfoDto.getName()) ? null : syTravelInfoDto.getName());
        syTravelInfoDto.setType(StringUtils.isEmpty(syTravelInfoDto.getType()) ? null : syTravelInfoDto.getType());
        syTravelInfoDto.setTravelType(StringUtils.isEmpty(syTravelInfoDto.getTravelType()) ? null : syTravelInfoDto.getTravelType());
        syTravelInfoDto.setRecommend(StringUtils.isEmpty(syTravelInfoDto.getRecommend()) ? null : syTravelInfoDto.getRecommend());
        BeanUtils.copyProperties(syTravelInfoDto, syTravelInfo);

        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();

       String name=syTravelInfoDto.getName();

        //根据条件查询
//        page.setRecords(this.syTravelInfoService.page(page, Wrappers.query(syTravelInfo)).getRecords());
         page.setRecords(this.syTravelInfoService.queryFuzzySearch(page,syTravelInfo));
        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 跳转到主页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping()
    public String index() {
        return PREFIX + "/syTravelInfo.html";
    }

    /**
     * 新增页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/syTravelInfo_add.html";
    }

    /**
     * 编辑页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/syTravelInfo_edit.html";
    }

//    /**
//     * 新增页面
//     *
//     * @author hst
//     * @Date 2021-08-06
//     */
//    @RequestMapping("/jddl/add")
//    public String jddlAdd() {
//        return PREFIX + "/syTravelInfoJddl_add.html";
//    }
//
//    /**
//     * 编辑页面
//     *
//     * @author hst
//     * @Date 2021-08-06
//     */
//    @RequestMapping("/jddl/edit")
//    public String jddlEdit() {
//        return PREFIX + "/syTravelInfoJddl_edit.html";
//    }

    /**
     * 跳转到热点推荐页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/jddl")
    public String jddlIndex() {
        return PREFIX + "/jddl/syTravelInfoJddl.html";
    }
    /**
     * 新增页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/jddl/add")
    public String jddlAdd() {
        return PREFIX + "/jddl/syTravelInfoJddl_add.html";
    }

    /**
     * 编辑页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/jddl/edit")
    public String jddlEdit() {
        return PREFIX + "/jddl/syTravelInfoJddl_edit.html";
    }

    /**
     * 跳转到热点推荐页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/rdtj")
    public String rdtjIndex() {
        return PREFIX + "/rdtj/syTravelInfoRdtj.html";
    }
    /**
     * 新增页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/rdtj/add")
    public String rdtjAdd() {
        return PREFIX + "/rdtj/syTravelInfoRdtj_add.html";
    }

    /**
     * 编辑页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/rdtj/edit")
    public String rdtjEdit() {
        return PREFIX + "/rdtj/syTravelInfoRdtj_edit.html";
    }
    /**
     * 跳转到热点推荐页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/jdzs")
    public String JdzsIndex() {
        return PREFIX + "/jdzs/syTravelInfoJdzs.html";
    }
    /**
     * 新增页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/jdzs/add")
    public String jdzsAdd() {
        return PREFIX + "/jdzs/syTravelInfoJdzs_add.html";
    }

    /**
     * 编辑页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/jdzs/edit")
    public String jdzsEdit() {
        return PREFIX + "/jdzs/syTravelInfoJdzs_edit.html";
    }
    /**
     * 跳转到热点推荐页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/yxsy")
    public String yxsyIndex() {
        return PREFIX + "/yxsy/syTravelInfoYxsy.html";
    }
    /**
     * 新增页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/yxsy/add")
    public String yxsyAdd() {
        return PREFIX + "/yxsy/syTravelInfoYxsy_add.html";
    }

    /**
     * 编辑页面
     *
     * @author hst
     * @Date 2021-08-06
     */
    @RequestMapping("/yxsy/edit")
    public String yxsyEdit() {
        return PREFIX + "/yxsy/syTravelInfoYxsy_edit.html";
    }

}
